package org.example.controller;

import org.example.annotation.CheckPermission;
import org.example.pojo.domain.OperationalMonitoring;
import org.example.result.Result;
import org.example.service.OperationalMonitoringService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/operational-monitoring")
public class OperationalMonitoringController {

    @Autowired
    private OperationalMonitoringService operationalMonitoringService;

    /**获取所有运营监控数据(admin)**/
    @CheckPermission({"admin"})
    @GetMapping("/list")
    public Result getAllMonitoringData() {
        List<OperationalMonitoring> monitoringData = operationalMonitoringService.getAllMonitoringData();
        return Result.success("所有运营监控数据",monitoringData);
    }

    /**根据监控ID获取运营监控数据(admin)**/
    @CheckPermission({"admin"})
    @GetMapping("/{monitorId}")
    public Result getMonitoringDataById(@PathVariable Integer monitorId) {
        OperationalMonitoring monitoring = operationalMonitoringService.getMonitoringDataById(monitorId);
        return Result.success("监控ID("+monitorId+")运营监控数据",monitoring);
    }

    /**添加运营监控数据(admin)**/
    @CheckPermission({"admin"})
    @PostMapping("/add")
    public Result addMonitoringData(@RequestBody OperationalMonitoring monitoring) {
        operationalMonitoringService.addMonitoringData(monitoring);
        return Result.success("运营监控数据添加成功！");
    }

    /**更新运营监控数据(admin)**/
    @CheckPermission({"admin"})
    @PutMapping("/update")
    public Result updateMonitoringData(@RequestBody OperationalMonitoring monitoring) {
        operationalMonitoringService.updateMonitoringData(monitoring);
        return Result.success("运营监控数据更新成功！");
    }

    /**删除运营监控数据(admin)**/
    @CheckPermission({"admin"})
    @DeleteMapping("/delete/{monitorId}")
    public Result deleteMonitoringData(@PathVariable Integer monitorId) {
        operationalMonitoringService.deleteMonitoringData(monitorId);
        return Result.success("运营监控数据删除成功！");
    }
}
